import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }],
  },

  // 准备导入的路由
  {
    path: '/import',
    component: Layout,
    children: [
      { path: '', component: () => import('@/views/import') }
    ]
  },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]


import departments from './modules/departments'
import employees from './modules/employees'
import setting from './modules/setting'
import salarys from './modules/salarys'
import social from './modules/social'
import attendances from './modules/attendances'
import approvals from './modules/approvals'
import permission from './modules/permission'
// 再准备一个放动态路由的数组
// 如果你再额外准备这个数组，那么到时候就根据权限可以决定这个数组里放哪些规则
// 可以根据权限来添加和删除
export const aysncRoutes = [
  attendances,approvals,departments,employees,permission,salarys,setting,social
]


const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 路由规则
  routes: [...constantRoutes,]
})


const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
